layui.use(['jquery','layer','form'],function() {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;

    var type = 2;
    form.on("radio(check)",function (data) {
        if (data.value == 2){
            type = 2;
        }else if (data.value == 3){
            type = 3;
        }
    });

    //确定
    var result;
    determine = function determine(){
        //获取当前登录用户
        var user = localStorage.getItem('user');
        user = JSON.parse(user);
        //添加审核记录
        if (type==2){
            result = 1;
        }else if(type==3){
            result = 3;
        }
        var param = {
            'courseId':$('#courseId').val(),
            'implementId':user.data.userId,
            'implementDate': getTime(),
            'result': result,
            'remarks':$('#remarks').val(),
            'type': 1,
        }
        console.log(param);
        $.ajax({
            url: '/applyRecord/addCourseRecord',
            data: param,
            type: 'post',
            dataType: 'json',
            success: function (data) {
                console.log("添加审核记录成功");
            }
        })
        //修改状态
        $.ajax({
            url: '/applyRecord/editApplyRecordById',
            data: {'result':type,'id':$('#JsApplyId').val()},
            type: 'post',
            dataType: 'json',
            success: function (data) {
            }
        })
        //添加审核日志
        var params = {
            'type':type,
            'userId':user.data.userId,
            'createDate':getTime(),
            'remark': $('#remarks').val(),
            'examineType':4,
            'userName':user.data.trueName,
            'examineId': $('#courseId').val()
        }
        $.ajax({
            url: '/applyRecord/addAuditLog',
            data: params,
            type: 'post',
            dataType: 'json',
            success: function (data) {
            }
        })
        var layer = parent.layer;
        layer.close(layer.index);
    }

    //取消
    cancel = function cancel(){
        var layer = parent.layer;
        layer.close(layer.index);
    }

    //现在时间
    function getTime(){
        var date=new Date();
        var year=date.getFullYear();
        var month=date.getMonth()+1;
        var day=date.getDate();
        var hour=date.getHours();
        var minute=date.getMinutes();
        var second=date.getSeconds();
        var dateStr = year+"-"+zeroFilling(month)+"-"+zeroFilling(day)+" "+zeroFilling(hour)+":"+zeroFilling(minute)+":"+zeroFilling(second);
        return dateStr;
    }
    function zeroFilling(data){
        if(data<10){
            data="0"+data;
        }
        return data;
    }

})
